package awt;

import java.awt.*;
import java.awt.event.*;

/**
 * @description:
 * @author: Tom
 * @create: 2019-07-26 17:24
 **/
public class ThreeListeners implements MouseListener, MouseMotionListener, WindowListener {

    private Frame f;
    private TextField t;

    public static void main(String[] args) {
        ThreeListeners threeListeners = new ThreeListeners();
        threeListeners.go();
    }

    private void go() {
        f = new Frame("Three Listeners example");
        f.add(new Label("Click and drag the mouse"), "North");
        t = new TextField(30);
        f.add(t, "South");
        f.addMouseMotionListener(this);
        f.addMouseListener(this);
        f.addWindowListener(this);
        f.setSize(300, 200);
        f.setVisible(true);

    }


    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    //是鼠标刚进入组件的时候调用(只调用一次)
    @Override
    public void mouseEntered(MouseEvent e) {
        t.setText("the Mouse Entered");

    }

    @Override
    public void mouseExited(MouseEvent e) {
        String s = "the Mouse has left ths Building";
        t.setText(s);

    }

    @Override
    public void mouseDragged(MouseEvent e) {
        String s = "Mouse dragging : X=" + e.getX() + " Y=" + e.getY();
        t.setText(s);
        System.out.println();

    }

    @Override
    public void mouseMoved(MouseEvent e) {

    }

    @Override
    public void windowOpened(WindowEvent e) {

    }

    @Override
    public void windowClosing(WindowEvent e) {
        System.exit(1);

    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {

    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    @Override
    public void windowActivated(WindowEvent e) {

    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }
}
